import { deletePostCategory, insertOnePostCategory, updateOnePostCategory, lookPostCategory, lookPostCategoryTree } from '@/api/postCategory'

const getDefaultState = () => {}

const state = getDefaultState()

const mutations = {}

const actions = {
  // 树展示
  async lookPostCategoryTree({ commit, state }) {
    return new Promise((resolve, reject) => {
      lookPostCategoryTree()
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 条件查询
  async lookPostCategory({ state }, postCategory) {
    return new Promise((resolve, reject) => {
      lookPostCategory(postCategory)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 添加一条岗位分类
  async insertOnePostCategory({ commit, state }, postCategory) {
    return new Promise((resolve, reject) => {
      insertOnePostCategory(postCategory)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改岗位分类
  async updateOnePostCategory({ commit, state }, postCategory) {
    return new Promise((resolve, reject) => {
      updateOnePostCategory(postCategory)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量删除岗位分类
  async deletePostCategory({ commit, state }, ids) {
    return new Promise((resolve, reject) => {
      deletePostCategory(ids)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
